package com.moly.websocketone.configuration.listener;

import com.moly.websocketone.listener.application.ApplicationListener;
import com.moly.websocketone.listener.request.RequestListener;
import com.moly.websocketone.listener.session.SessionListener;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.servlet.ServletRequestListener;
import javax.servlet.http.HttpSessionListener;

/**
 * @Description:  用于注册监听器
 * @Author: m01
 * @Date: created at  2018/11/13  15:33
 * @Modified By:
 */
@Configuration
public class RegisteryListener {

    @Bean
    public ServletListenerRegistrationBean  registApplicationListener(){
        ServletListenerRegistrationBean servletListenerRegistrationBean = new ServletListenerRegistrationBean();
        servletListenerRegistrationBean.setListener( new ApplicationListener());
        return servletListenerRegistrationBean;
    }

    @Bean
    public ServletListenerRegistrationBean<HttpSessionListener>  registSessionListener(){
        ServletListenerRegistrationBean<HttpSessionListener> servletListenerRegistrationBean = new ServletListenerRegistrationBean<HttpSessionListener>();
        servletListenerRegistrationBean.setListener( new SessionListener());
        return servletListenerRegistrationBean;
    }

    @Bean
    public ServletListenerRegistrationBean<ServletRequestListener> registRequestListener(){
        ServletListenerRegistrationBean<ServletRequestListener> servletListenerRegistrationBean = new ServletListenerRegistrationBean<ServletRequestListener>();
        servletListenerRegistrationBean.setListener( new RequestListener());
        return servletListenerRegistrationBean;
    }
}
